//
//  DSBaseRequest.m
//  DaBaiService
//
//  Created by Mac-Mini-KingVision on 15/9/18.
//  Copyright (c) 2015年 Mac-Mini-KingVision. All rights reserved.
//

#import "LYBaseRequest.h"
#import "LYBaseErrorResponse.h"
#import "LYProgressHUDManager.h"
#import "LWMarco.h"
#import <NSObject+MJKeyValue.h>
@implementation LYBaseRequest


-(NSTimeInterval)requestTimeoutInterval
{
    return 30;
}



-(void)requestCompleteFilter
{
    [super requestCompleteFilter];
    
    
    LYBaseErrorResponse *error = [LYBaseErrorResponse mj_objectWithKeyValues:self.responseString];
//    HYLog([self disposeFailedResponse]);
    NSLog(@"%d",[self disposeFailedResponse]);
    
    if ([error.code isEqualToString:@"102030"]) {
        //token过期
        [self stop];
        [self logout];
        return;
    }
    
    
    
    if (![self disposeFailedResponse]) {
        if (!IsStrEmpty(error.code)) {
            [LYProgressHUDManager showTipsInWindowWithOnlyText:error.message];
            self.successCompletionBlock = nil;
            self.failureCompletionBlock = nil;
        }
    }
    
    
//    [GiFHUD dismiss];
//    DSErrorResponse *response = [DSErrorResponse mj_objectWithKeyValues:self.responseString];
//    if ([response.code isEqualToString:ERROR_TOKENPASS]) {
//        [GiFHUD dismiss];
//        [[SPKitExample sharedInstance] exampleLogout];
//        [DSConfigureManager logout];
//        return;
//    }else if (!IsStrEmpty(response.code)){
//        [DSTipsManager showTipsInWindowWithOnlyText:response.message];
////        self.successCompletionBlock = nil;
////        return;
//    }
}

-(void)requestFailedFilter
{
    [super requestFailedFilter];
//    [GiFHUD dismiss];
//    if (![self.requestOperation isCancelled]) {
////        [DSTipsManager showTipsInWindowWithOnlyText:@"网络错误，请稍后再试"];
////        [SVProgressHUD showInfoWithStatus:@"网络错误，请稍后再试"];
//    }
    
}

-(NSDictionary *)baseRequestUrlArguments
{
//    NSString *login = [[DBSUserCenter shareInstance] login];
//    login = IsStrEmpty(login) ? @"" : login;
//    return @{@"login":login};
    return nil;
}

-(id)requestArgument
{
    NSDictionary *dic = [self baseRequestUrlArguments];
    NSDictionary *appDic = [self requestAppendArgument];
    NSMutableDictionary *resultDic = [NSMutableDictionary dictionaryWithDictionary:dic];
    for (NSString *key in appDic.allKeys) {
        [resultDic setObject:appDic[key] forKey:key];
    }
    return resultDic;
}

-(BOOL)disposeFailedResponse
{
    return NO;
}

-(id)requestAppendArgument
{
    return nil;
}

-(YTKRequestMethod)requestMethod
{
    return YTKRequestMethodPost;
}

-(void)logout
{
    
}


@end
